<?php
class ProductGroupsController extends AppController {
 var $name = "ProductGroups";	
 var $helpers = array('Html','Ajax','Javascript','Form');
 /*var $paginate = array(
        'limit' =>10,
        'order' => array('ProductGroup.name' => 'asc')
    );*/
    
    function index2($id = null) {
        $this->layout = "home";
        $this->Product_group->id = $id;
        $this->set('iProduct_group', $this->ProductGroup->read());
        $this->set('product_group', $this->ProductGroup->find('all', array('order' => array('ProductGroup.id DESC'))));
		$this->set('product_group_view', $this->ProductGroup->find('all', array('order' => array('ProductGroup.id DESC'))));
    }
    
  function quick_create() {
        $parent = $_REQUEST['id'];
        $menuString = $_REQUEST['menus'];
        $des = $_REQUEST['description'];
        $list = strtok($menuString, ".");
        while ($list != false) {
            $this->ProductGroup->create();
            $this->ProductGroup->set('name', $list);
            $this->ProductGroup->set('parent_group_id', $parent);
            $this->ProductGroup->set('description', $des);
            $this->ProductGroup->saveAll();
            $list = strtok(".");
        }
        $this->redirect(array('action'=>'index2'));
  }
    
  function index($id = null) {
        $this->layout = "home";
        $this->Product_group->id = $id;
        $this->set('iProduct_group', $this->ProductGroup->read());
        $this->set('product_group', $this->ProductGroup->find('all'));
		$this->set('product_group_view', $this->ProductGroup->find('all'));
		
		//$data = $this->paginate('ProductGroup');
        //$this->set('product_group', $data);
	 }
    
    function save() {
        $id = $_REQUEST['id'];
        $name = $_REQUEST['name'];
        $parent_group_id = $_REQUEST['parent_group_id'];
		if($parent_group_id ==null){
			$parent_group_id =0;
		}
        $description = $_REQUEST['description'];
        
        if (($id != null) && ($id != "")) {
            $this->ProductGroup->id = $id;
            $this->ProductGroup->set('name', $name);
            $this->ProductGroup->set('parent_group_id', $parent_group_id);
			$this->ProductGroup->set('description', $description);
            $this->ProductGroup->save();
        } else {
            $this->ProductGroup->create();
            $this->ProductGroup->set('name', $name);
            $this->ProductGroup->set('parent_group_id', $parent_group_id);
			$this->ProductGroup->set('description', $description);
            $this->ProductGroup->saveAll();
        }
        $this->redirect(array("action" => "index"));
    }
	function delete() {
		$id= $_REQUEST['id'];
		if($id !=null && $id !=""){
		$this->ProductGroup->delete($id);
		$this->redirect(array('action'=>'index'));
		}
}
}
?>